﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CrystalReportsManagementSystem
{
    public partial class Site : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
                return;
            if (NewStartHanldingUI.CurrentUser.CurrentUser.Instance.UserCode != null)
            {
                GenerateMenuItem();
            }
        }
        private void GenerateMenuItem()
        {
            foreach (NewStartModels.Models.Menus.IMenu item in NewStartHanldingUI.CurrentUser.CurrentUser.Instance.Menus)
            {
                MenuItem MItem = new MenuItem(item.MenuName);
                MItem.Text = item.MenuName;
                MItem.Value = item.MenuUID.ToString();
                if (item.ParentUID <= 0)
                {
                    MItem.Selectable = false;
                    this.Menu1.Items.Add(MItem);
                }
                else
                {
                    GenerateMenuItem(this.Menu1.Items, item, MItem);
                }
            }
        }
        private void GenerateMenuItem(MenuItemCollection Items, NewStartModels.Models.Menus.IMenu item, MenuItem NewMenu)
        {
            foreach (MenuItem menu in Items)
            {
                if (menu.Value == item.ParentUID.ToString())
                {
                    menu.ChildItems.Add(NewMenu);
                }
                else
                    GenerateMenuItem(menu.ChildItems, item, NewMenu);
            }
        }

        protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
        {
            //CrystalReportsView reportview = new CrystalReportsView();
            //reportview.ReportFile = e.Item.Text;
            Response.Redirect("CrystalReportsViewer.aspx?ReportFile=" + e.Item.Text, false);
        }
    }
}